#include <graphics.h>
#include <conio.h>
#define high 480
#define width 640
#define ballnum 5
 
int main()
{
    float ball_x[ballnum],ball_y[ballnum];
    float ball_vx[ballnum],ball_vy[ballnum];
    float radius;
    int i;
    radius=20;
    for(i=0;i<ballnum;i++)
    {
        ball_x[i]=(i+2)*radius*3;
        ball_y[i]=high/2;
        ball_vx[i]=1;
        ball_vy[i]=1;
    }
    initgraph(width,high);
    BeginBatchDraw();
    while(1)
    {
        setcolor(BLACK);
        setfillcolor(BLACK);
        for(i=0;i<ballnum;i++)
        {
            fillcircle(ball_x[i],ball_y[i],radius);
        }
        for(i=0;i<ballnum;i++)
        {
            ball_x[i]=ball_x[i]+ball_vx[i];
            ball_y[i]=ball_y[i]+ball_vy[i];
        }
        for(i=0;i<ballnum;i++)
        {
            if((ball_x[i]<=radius)||(ball_x[i]>=width-radius))
                ball_vx[i]=-ball_vx[i];
            if((ball_y[i]<=radius)||(ball_y[i]>=high-radius))
                ball_vy[i]=-ball_vy[i];
        }
        setcolor(YELLOW);
        setfillcolor(GREEN);
        for(i=0;i<ballnum;i++)
        {
            fillcircle(ball_x[i],ball_y[i],radius);
        }
        FlushBatchDraw();
        sleep(3);
    }
    EndBatchDraw;
    closegraph;
    return 0;
}

